{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# JFreeChart Versions - Diving into Differences and Similarities"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook reports code and results of the analysis conducted on the two versions of the _JfreeChart_ software system included in the dataset (i.e. $0.6.0$ and $0.7.1$). \n",
    "\n",
    "The goal of the analysis is to provide insights on the differences and/or similarities between the methods included in both systems, along with some considerations on the coherence of methods included _only_ in one of the two.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Utilities \n",
    "\n",
    "Utilities functions used throughout this notebook. \n",
    "Feel free to **skip** to the <a href=\"#analysis\">**Analisys Section**</a> directly."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Preamble"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# %load preamble_directives.py\n",
    "\"\"\"Some imports and path settings to make notebook code\n",
    "running smoothly.\n",
    "\"\"\"\n",
    "# Author: Valerio Maggio <valeriomaggio@gmail.com>\n",
    "# Copyright (c) 2015 Valerio Maggio <valeriomaggio@gmail.com>\n",
    "# License: BSD 3 clause\n",
    "\n",
    "import sys, os\n",
    "# Extending PYTHONPATH to allow relative import!\n",
    "sys.path.append(os.path.join(os.path.abspath(os.path.curdir), '..'))\n",
    "\n",
    "# Import Django Settings\n",
    "from django.conf import settings\n",
    "# Import Comments_Classification (Django) Project Settings\n",
    "from comments_classification import settings as comments_classification_settings\n",
    "\n",
    "try:\n",
    "    settings.configure(**comments_classification_settings.__dict__)\n",
    "except RuntimeError:\n",
    "    # settings already configured\n",
    "    pass\n",
    "\n",
    "# ---------------------\n",
    "# Module Import Section\n",
    "# ---------------------\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Text Processing Functions (for code and comments)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import re\n",
    "\n",
    "def strip_tags(text):\n",
    "    \"\"\"Strips all HTML tags from text\"\"\"\n",
    "    HTML_TAG_RE = re.compile(r'<[^>]+>')\n",
    "    return HTML_TAG_RE.sub('', text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from string import punctuation\n",
    "\n",
    "def strip_punctuations(text, allowed='@'):\n",
    "    \"\"\"Strips all the punctuation character from the input comment.\n",
    "    \n",
    "    Parameters\n",
    "    ----------\n",
    "    text : str\n",
    "        The input text to process\n",
    "\n",
    "    allowed : str, optional. \n",
    "        The list of punctuation characters to exclude from the processing\n",
    "        (default is '@' as for JavaDoc Comments).\n",
    "    \n",
    "    \"\"\"\n",
    "    black_list = punctuation\n",
    "    for c in allowed:\n",
    "        black_list = black_list.replace(c, '')\n",
    "    for p in black_list:\n",
    "        text = text.replace(p, ' ')\n",
    "    return '\\n'.join(' '.join(w for w in line.split() if len(w)) for line in text.splitlines() if len(line))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def normalise_lines(text):\n",
    "    \"\"\"Removes additional (trailing) spaces from lines of the given text and \n",
    "    returns it normalised (no extra spaces)\"\"\"\n",
    "    return '\\n'.join(l.strip() for l in text.splitlines() if len(l.strip()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def extract_locs(code_fragment):\n",
    "    \"\"\"Normalise and returns the lines of code in the input fragment.\"\"\"\n",
    "    locs = ' '.join(l.strip() for st in code_fragment.split(';') for l in st.splitlines() \n",
    "                    if len(l.strip()) and len(strip_punctuations(l.strip())))\n",
    "    return locs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pipeline Process\n",
    "Helper class that aids the creation and the application of multiple text processing functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class Pipeline(object):\n",
    "    \"\"\"Implements a simple linear pipeline process\"\"\"\n",
    "    \n",
    "    def __init__(self, *callables):\n",
    "        \"\"\"Creates a new Pipeline of processes (i.e. `callables`.)\n",
    "        Each of this callable, must always return a value as it \n",
    "        will represent the new `data` parameter passed through \n",
    "        the pipeline till finally returned.\n",
    "        \n",
    "        Parameters\n",
    "        ----------\n",
    "        callables : list\n",
    "            A list of callables (e.g. functions) of arity one.\n",
    "            This list constitutes the set of filters of the pipeline.\n",
    "        \"\"\"\n",
    "        self._filters = list(callables)\n",
    "        \n",
    "    @property\n",
    "    def filters(self):\n",
    "        return self._filters\n",
    "\n",
    "    def __iadd__(self, process):\n",
    "        if not callable(process):\n",
    "            raise ValueError('The value should be a callable')\n",
    "        \n",
    "        from inspect import signature\n",
    "        sig_process = signature(process)\n",
    "        if len(sig_process.parameters) != 1:\n",
    "            raise ValueError('The input function must have arity one!')\n",
    "            \n",
    "        self._filters.append(process)\n",
    "        return self\n",
    "    \n",
    "    def process(self, data):\n",
    "        \"\"\"Execute the pipeline\"\"\"\n",
    "        for callable in self._filters:\n",
    "            data = callable(data)\n",
    "        return data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Function to Analyse Coherence"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "NOT_EVALUATED = -1\n",
    "DONT_KNOW = 2\n",
    "FURTHER_EVAL = 5\n",
    "AGREEMENT = 3\n",
    "STRONG_AGREEMENT = 4 \n",
    "\n",
    "def is_coherent(method):\n",
    "    \"\"\"Return wheter or not comment is coherent with its method implementation according to judges evaluations.\n",
    "    \n",
    "    Parameters\n",
    "    ----------\n",
    "    method : `source_code_analysis.models.CodeMethod`\n",
    "        Instance of a `CodeMethod` model holding the reference to its corresponding evaluations.\n",
    "        \n",
    "    Returns\n",
    "    -------\n",
    "    bool : \n",
    "        True if the evaluation (the first one retrieved from the db) corresponds to an\n",
    "        AGREEMENT | STRONG_AGREEMENT value.\n",
    "    \"\"\"\n",
    "    return (method.agreement_evaluations.last().agreement_vote in (AGREEMENT, STRONG_AGREEMENT))\n",
    "\n",
    "def has_agreement_evaluations(method):\n",
    "    \"\"\"Check that input methods has agreement evaluations interesting for the current analysis\n",
    "    (i.e. different from DONT_KNOW).\n",
    "    \n",
    "    Parameters\n",
    "    ----------\n",
    "    method : `source_code_analysis.models.CodeMethod`\n",
    "        Instance of a `CodeMethod` model holding the reference to its corresponding evaluations.\n",
    "        \n",
    "    Returns\n",
    "    -------\n",
    "    bool : \n",
    "        True if the evaluation (the first one retrieved from the db) does **not** \n",
    "        correspond to a DONT_KNOW value.\n",
    "    \"\"\"\n",
    "    return (method.agreement_evaluations.last().agreement_vote not in (NOT_EVALUATED, \n",
    "                                                                       DONT_KNOW, FURTHER_EVAL))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Functions to gather Data from the DB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def signature(code_fragment):\n",
    "    \"\"\"Returns the signature of a method extracted from the input code fragment.\n",
    "    \n",
    "    Parameters\n",
    "    ----------\n",
    "    code_fragment : str\n",
    "        The implementation code of a method (i.e. method.code_fragment attribute)\n",
    "        \n",
    "    Returns\n",
    "    -------\n",
    "    str :\n",
    "        The signature string of the method\n",
    "    \n",
    "    \"\"\"\n",
    "    first_line = code_fragment[:code_fragment.find('{')]\n",
    "    return ' '.join([l.strip() for l in first_line.splitlines() if len(l.strip())])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def gather_all_methods(sw_project):\n",
    "    \"\"\"Gather all methods for the input software project\n",
    "    \n",
    "    Parameters\n",
    "    ----------\n",
    "    sw_project : `source_code_analysis.models.SoftwareProject`\n",
    "        Target Software Project\n",
    "        \n",
    "    Returns\n",
    "    -------\n",
    "    dict : \n",
    "        A dictionary mapping all methods with its unique key.\n",
    "        This key is extremely important to correctly identify similarities among \n",
    "        multiple versions of the same software. \n",
    "    \n",
    "        In more details, the key for a single *method* is defined by the following triple:\n",
    "\n",
    "        * Name of the Source File\n",
    "        * Name of the Class\n",
    "        * Signature of the method\n",
    "    \"\"\"\n",
    "    \n",
    "    # gather all methods\n",
    "    methods = filter(has_agreement_evaluations, sw_project.code_methods.all())\n",
    "    \n",
    "    # create the map\n",
    "    methods_map = dict()\n",
    "    for method in methods:\n",
    "        key = '{}{}{}'.format(method.code_class.src_filename, \n",
    "                              method.code_class.class_name, \n",
    "                              signature(method.code_fragment))\n",
    "        if not key in methods_map:\n",
    "            methods_map[key] = method\n",
    "        else:\n",
    "            print('Key already present: ')\n",
    "            print('Current method ID: ', method.id)\n",
    "            print('Already present method: ', methods_map[key].id)\n",
    "    \n",
    "    # return map\n",
    "    return methods_map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Utility function to test processing results and check what's going on"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def randomly_pick_a_method_from(list_of_methods_keys, with_code=False, with_coherence=False):\n",
    "    \"\"\"Randomly pick a method from the input collection of keys and print the \n",
    "    corresponding lead comments. If `with_code` parameter is provided, \n",
    "    the code_fragment is printed as well.\n",
    "    Moreover, if the `with_coherence` parameter is True, the corresponding coherence evaluation is \n",
    "    reported in the output, as well.\n",
    "    \"\"\"\n",
    "    \n",
    "    from random import choice\n",
    "    random_key = choice(list_of_methods_keys)\n",
    "\n",
    "    method_in_jf060 = jf060_methods[random_key]\n",
    "    method_in_jf071 = jf071_methods[random_key]\n",
    "\n",
    "    print('='*80)\n",
    "    print('Method in JFreeChart 0.6.0', end=' ')\n",
    "    if with_coherence:\n",
    "        print('Is Coherent: ', is_coherent(method_in_jf060))\n",
    "    else:\n",
    "        print('')\n",
    "    \n",
    "    print(method_in_jf060.comment)\n",
    "    if with_code:\n",
    "        print('')\n",
    "        print(method_in_jf060.code_fragment)\n",
    "    \n",
    "    print('\\n\\n')\n",
    "    \n",
    "    print('Method in JFreeChart 0.7.1', end=' ')\n",
    "    if with_coherence:\n",
    "        print('Is Coherent: ', is_coherent(method_in_jf071))\n",
    "    else:\n",
    "        print('')\n",
    "        \n",
    "    print(method_in_jf071.comment)\n",
    "    if with_code:\n",
    "        print('')\n",
    "        print(method_in_jf071.code_fragment)\n",
    "    \n",
    "    print('='*80, end='\\n\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"analysis\"></a>\n",
    "\n",
    "# Analysis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### <a name=\"nav\"></a>\n",
    "\n",
    "* <a href=\"#data\">Load Data</a>\n",
    "\n",
    "* <a href=\"#common_methods\">Analysis of Methods in Common</a> (<a href=\"#comments_stats\">Stats</a>)\n",
    "    \n",
    "    - <a href=\"#analysis_comment\">Analysis of Comments</a>\n",
    "        - <a href=\"#same_comment\">Methods with Same Comment</a>\n",
    "            - <a href=\"#tw01\">Take Away No. 1</a>\n",
    "        - <a href=\"#diff_comment\">Methods with Different Comment</a>\n",
    "            - <a href=\"#tw02\">Take Away No. 2</a>\n",
    "            \n",
    "    - <a href=\"#analysis_code\">Analysis of Implementation</a>\n",
    "        - <a href=\"#scomm_code\">Methods with Same Comment</a>\n",
    "            - <a href=\"#tw03\">Take Away No. 3</a>\n",
    "        - <a href=\"#dcomm_code\">Methods with Different Comment</a>\n",
    "            - <a href=\"#tw04\">Take Away No. 4</a>\n",
    "            \n",
    "    - <a href=\"#analysis_coherence\">Analysis of Coherence</a>\n",
    "    \n",
    "        - <a href=\"#scomm_scode_coherence\">Methods with Same Comment and Code</a>\n",
    "        - <a href=\"#scomm_dcode_coherence\">Methods with Same Comment, Different Code</a>\n",
    "            - <a href=\"#tw05\">Take Away No. 5</a>\n",
    "        - <a href=\"#dcomm_scode_coherence\">Methods with Different Comment, Same Code</a>\n",
    "            - <a href=\"#tw06\">Take Away No. 6</a>\n",
    "            - <a href=\"#tw07\">Take Away No. 7</a>\n",
    "        - <a href=\"#dcomm_dcode_coherence\">Methods with Different Comment and Code</a>\n",
    "            - <a href=\"#tw08\">Take Away No. 8</a>\n",
    "            - <a href=\"#tw09\">Take Away No. 9</a>\n",
    "        \n",
    "* <a href=\"#difference_methods\">Analysis of Methods NOT in Common</a>\n",
    "    - <a href=\"#diff_jf060\">Coherence of Methods in JFreeChart 0.6.0</a>\n",
    "    - <a href=\"#diff_jf071\">Coherence of Methods in JFreeChart 0.7.1</a>\n",
    "    - <a href=\"#match\">(Likely) Modified Methods from JFreeChart 0.6.0 to 0.7.1</a>\n",
    "\n",
    "* <a href=\"#summary\">Summary</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"data\"></a>\n",
    "\n",
    "# Load Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from source_code_analysis.models import SoftwareProject"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "jfreechart_060 = SoftwareProject.objects.get(name__iexact='JFreeChart', version='0.6.0')\n",
    "jfreechart_071 = SoftwareProject.objects.get(name__iexact='JFreeChart', version='0.7.1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "jf060_methods = gather_all_methods(jfreechart_060)\n",
    "jf071_methods = gather_all_methods(jfreechart_071)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Total Stats _(starting point)_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total No. of Methods in JFreeChart 0.6.0:  461\n",
      "Total No. of Methods in JFreeChart 0.7.1:  588\n"
     ]
    }
   ],
   "source": [
    "print('Total No. of Methods in JFreeChart 0.6.0: ', len(jf060_methods))\n",
    "print('Total No. of Methods in JFreeChart 0.7.1: ', len(jf071_methods))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"common_methods\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "# Common Methods"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Methods in Common:  283\n"
     ]
    }
   ],
   "source": [
    "# Set of all the Keys in common between the two considered versions\n",
    "methods_in_common = set(jf060_methods.keys()).intersection(set(jf071_methods.keys()))\n",
    "print('Total Methods in Common: ', len(methods_in_common))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"analysis_comment\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "## Analysis of the Comments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Set the Pipelines\n",
    "comment_pipeline = Pipeline(strip_tags, strip_punctuations, normalise_lines)\n",
    "\n",
    "# List to store the references to methods \n",
    "# sharing (or not) the same comment between the two versions\n",
    "same_comment = list()\n",
    "different_comment = list()\n",
    "    \n",
    "for mkey in methods_in_common:\n",
    "    comment_in_060 = comment_pipeline.process(jf060_methods[mkey].comment)\n",
    "    comment_in_071 = comment_pipeline.process(jf071_methods[mkey].comment)\n",
    "    \n",
    "    if comment_in_060 == comment_in_071:\n",
    "        same_comment.append(mkey)\n",
    "    else:\n",
    "        different_comment.append(mkey)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"comments_stats\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "#### Stats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Number of Methods in Common:  283\n",
      "\t No. of those Sharing the Same Comment:  257\n",
      "\t No. of those With Differences in Comment:  26\n"
     ]
    }
   ],
   "source": [
    "print('Total Number of Methods in Common: ', len(methods_in_common))\n",
    "print('\\t No. of those Sharing the Same Comment: ', len(same_comment))\n",
    "print('\\t No. of those With Differences in Comment: ', len(different_comment))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"same_comment\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Methods in Common with the Same Comment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 \n",
      "/**\n",
      "   * Returns the width of each bar in the chart.\n",
      "   * @param area The area within which the plot will be drawn.\n",
      "   */\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 \n",
      "/**\r\n",
      "\n",
      "   * Returns the width of each bar in the chart.\r\n",
      "\n",
      "   * @param area The area within which the plot will be drawn.\r\n",
      "\n",
      "   */\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 \n",
      "/**\r\n",
      "   * Sets a reference to the plot that the axis is assigned to.\r\n",
      "   * <P>\r\n",
      "   * This method is called by Plot in the setHorizontalAxis() and setVerticalAxis() methods.\r\n",
      "   * You shouldn't need to call the method yourself.\r\n",
      "   * @param plot The plot that the axis belongs to.\r\n",
      "   */\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 \n",
      "/**\r\n",
      "\n",
      "   * Sets a reference to the plot that the axis is assigned to.\r\n",
      "\n",
      "   * <P>\r\n",
      "\n",
      "   * This method is called by Plot in the setHorizontalAxis() and setVerticalAxis() methods.\r\n",
      "\n",
      "   * You shouldn't need to call the method yourself.\r\n",
      "\n",
      "   * @param plot The plot that the axis belongs to.\r\n",
      "\n",
      "   */\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 \n",
      "/**\r\n",
      "   * Sets the label for the axis.\r\n",
      "   * <P>\r\n",
      "   * Registered listeners are notified of a general change to the axis.\r\n",
      "   * @param label The new label for the axis (null permitted).\r\n",
      "   */\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 \n",
      "/**\r\n",
      "\n",
      "   * Sets the label for the axis.\r\n",
      "\n",
      "   * <P>\r\n",
      "\n",
      "   * Registered listeners are notified of a general change to the axis.\r\n",
      "\n",
      "   * @param label The new label for the axis (null permitted).\r\n",
      "\n",
      "   */\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 \n",
      "/**\r\n",
      "   * Returns the color/shade used for the tick labels.\r\n",
      "   * @return The color/shade used for the tick labels.\r\n",
      "   */\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 \n",
      "/**\r\n",
      "\n",
      "   * Returns the color/shade used for the tick labels.\r\n",
      "\n",
      "   * @return The color/shade used for the tick labels.\r\n",
      "\n",
      "   */\n",
      "================================================================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Test: get a random key and check that they actually share the same comments \n",
    "# regardless the formattings (e.g. trailing spaces)\n",
    "randomly_pick_a_method_from(same_comment)  # Test 1\n",
    "randomly_pick_a_method_from(same_comment)  # Test 2\n",
    "randomly_pick_a_method_from(same_comment)  # Test 3\n",
    "randomly_pick_a_method_from(same_comment)  # Test 4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"tw01\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Take Away No. 1\n",
    "From the total set of $283$ methods in common between JFreeChart 0.6.0 and 0.7.1, \n",
    "\n",
    "* $257$ ($\\approx 91\\%$) have no significant differences in comments (differences limited **only** to text formattings and punctuaction characters)\n",
    "    - Hence this changes do **not** affect the coherence evaluation in any way."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"diff_comment\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Methods in Common with Different Comments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 \n",
      "/**\r\n",
      "   * Standard constructor: builds a DateAxis with mostly default attributes.\r\n",
      "   */\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 \n",
      "/**\r\n",
      "\n",
      "   * Constructs a date axis, using default values where necessary.\r\n",
      "\n",
      "   * @param label The axis label.\r\n",
      "\n",
      "   */\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 \n",
      "/**\r\n",
      "   * Sets the gap between the last bar in one category and the first bar in the\r\n",
      "   * next category, and notifies registered listeners that the plot has been modified.\r\n",
      "   * @param gap The new gap value.\r\n",
      "   */\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 \n",
      "/**\r\n",
      "\n",
      "   * Sets the gap between the last bar in one category and the first bar in the\r\n",
      "\n",
      "   * next category, and notifies registered listeners that the plot has been modified.\r\n",
      "\n",
      "   * @param percent The new gap value, expressed as a percentage of the width of the plot area\r\n",
      "\n",
      "   *        (0.05 = 5 percent).\r\n",
      "\n",
      "   */\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 \n",
      "/**\r\n",
      "   * Full constructor - builds a new DateTitle with the specified attributes.\r\n",
      "   * @param location the relative location of this title (use constants in AbstractTitle);\r\n",
      "   * @param alignment the text alignment of this title (use constants in AbstractTitle);\r\n",
      "   * @param dateStyle the Date style to use (SHORT, MEDIUM, LONG, or FULL constants from\r\n",
      "   *          java.text.DateFormat);\r\n",
      "   * @param locale the locale to use to format this date (if you are unsure what to use here, use\r\n",
      "   *         Locale.getDefault() for your default locale);\r\n",
      "   * @param font the font used to display the date;\r\n",
      "   * @param paint the paint used to display the date;\r\n",
      "   * @param insets the blank space around the outside of the title;\r\n",
      "   */\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 \n",
      "/**\r\n",
      "\n",
      "   * Constructs a new DateTitle with the specified attributes.\r\n",
      "\n",
      "   * @param location the relative location of this title (use constants in AbstractTitle).\r\n",
      "\n",
      "   * @param alignment the text alignment of this title (use constants in AbstractTitle).\r\n",
      "\n",
      "   * @param dateStyle the Date style to use (SHORT, MEDIUM, LONG, or FULL constants from\r\n",
      "\n",
      "   *          java.text.DateFormat).\r\n",
      "\n",
      "   * @param locale the locale to use to format this date (if you are unsure what to use here, use\r\n",
      "\n",
      "   *         Locale.getDefault() for your default locale).\r\n",
      "\n",
      "   * @param font the font used to display the date.\r\n",
      "\n",
      "   * @param paint the paint used to display the date.\r\n",
      "\n",
      "   * @param insets the blank space around the outside of the title.\r\n",
      "\n",
      "   */\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 \n",
      "/**\r\n",
      "   * Calculates and returns the value of the lowest visible tick on the axis.\r\n",
      "   */\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 \n",
      "/**\r\n",
      "\n",
      "   * Calculates the value of the lowest visible tick on the axis.\r\n",
      "\n",
      "   * @return The value of the lowest visible tick on the axis.\r\n",
      "\n",
      "   */\n",
      "================================================================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Qualitative Analysis (preliminary)\n",
    "\n",
    "randomly_pick_a_method_from(different_comment)  # Test 1\n",
    "randomly_pick_a_method_from(different_comment)  # Test 2\n",
    "randomly_pick_a_method_from(different_comment)  # Test 3\n",
    "randomly_pick_a_method_from(different_comment)  # Test 4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"tw02\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Take Away No. 2: \n",
    "At a first glance, considering the comments of the methods included in the list of $26$ those with _different comments_, **differences** appear quite resonable (thus not only limited to layout and formattings)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"analysis_code\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "## Analysis of the Implementation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"scomm_code\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Analysis of the Implementation for Methods with the Same Comment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "methods_with_same_comments = same_comment  # code readability purposes\n",
    "\n",
    "# Set the Pipeline\n",
    "code_pipeline = Pipeline(extract_locs)\n",
    "\n",
    "same_comment_and_code = list()\n",
    "same_comment_different_code = list()\n",
    "\n",
    "for mkey in methods_with_same_comments:\n",
    "    code_in_060 = code_pipeline.process(jf060_methods[mkey].code_fragment)\n",
    "    code_in_071 = code_pipeline.process(jf071_methods[mkey].code_fragment)\n",
    "        \n",
    "    if code_in_060 == code_in_071:\n",
    "        same_comment_and_code.append(mkey)\n",
    "    else:\n",
    "        same_comment_different_code.append(mkey)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Number of Common Methods with the same comments:  257\n",
      "\t No. of those Sharing the Same Code:  225\n",
      "\t No. of those With Differences in Code:  32\n"
     ]
    }
   ],
   "source": [
    "print('Total Number of Common Methods with the same comments: ', len(methods_with_same_comments))\n",
    "print('\\t No. of those Sharing the Same Code: ', len(same_comment_and_code))\n",
    "print('\\t No. of those With Differences in Code: ', len(same_comment_different_code))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"tw03\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Take Away No. 3: \n",
    "\n",
    "Among the $257$ methods **in common** between the two version that shares the same comment:\n",
    "\n",
    "* $225$ methods ($\\approx 88\\%$) have no difference in the implementation\n",
    "* $32$ methods have changes in code (and thus **not** in comments)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"dcomm_code\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Analysis of the Implementation for Methods with Different Comments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "methods_with_different_comments = different_comment  # code readability purposes\n",
    "\n",
    "# Set the Pipeline\n",
    "code_pipeline = Pipeline(extract_locs)\n",
    "\n",
    "different_comment_same_code = list()\n",
    "different_comment_and_code = list()\n",
    "\n",
    "for mkey in methods_with_different_comments:\n",
    "    code_in_060 = code_pipeline.process(jf060_methods[mkey].code_fragment)\n",
    "    code_in_071 = code_pipeline.process(jf071_methods[mkey].code_fragment)\n",
    "        \n",
    "    if code_in_060 == code_in_071:\n",
    "        different_comment_same_code.append(mkey)\n",
    "    else:\n",
    "        different_comment_and_code.append(mkey)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Number of Common Methods with different comments:  26\n",
      "\t No. of those Sharing the Same Code:  16\n",
      "\t No. of those With Differences in Code:  10\n"
     ]
    }
   ],
   "source": [
    "print('Total Number of Common Methods with different comments: ', len(methods_with_different_comments))\n",
    "print('\\t No. of those Sharing the Same Code: ', len(different_comment_same_code))\n",
    "print('\\t No. of those With Differences in Code: ', len(different_comment_and_code))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"tw04\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Take Away No. 4: \n",
    "\n",
    "Among the $26$ methods **in common** between the two version that have differences in their lead comments:\n",
    "\n",
    "* $16$ methods ($\\approx 62\\%$) have no difference in the implementation\n",
    "* $10$ methods have changes in code (**as well as** in comments)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"analysis_coherence\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "## Analysis of the Coherence"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"scomm_scode_coherence\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Coherence of  Methods with Same Comments and Code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "same_coherence = list()\n",
    "coherence_changed = list()\n",
    "\n",
    "for mkey in same_comment_and_code:\n",
    "    mth_in_060 = jf060_methods[mkey]\n",
    "    mth_in_071 = jf071_methods[mkey]\n",
    "    \n",
    "    if is_coherent(mth_in_060) == is_coherent(mth_in_071):\n",
    "        same_coherence.append(mkey)\n",
    "    else:\n",
    "        coherence_changed.append(mkey)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Number of Methods Sharing the same Lead Comment and Code\n",
      "\t Same Coherence:  225\n",
      "\t Different Coherence 0\n"
     ]
    }
   ],
   "source": [
    "print('Total Number of Methods Sharing the same Lead Comment and Code')\n",
    "print('\\t Same Coherence: ', len(same_coherence))\n",
    "print('\\t Different Coherence', len(coherence_changed))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Result\n",
    "No differences occur in the evaluation of coherences for common methods sharing the same code and comments (**as expected**)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"scomm_dcode_coherence\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Coherence of Methods with Same Comments but Different Code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "same_coherence = list()\n",
    "coherence_changed = list()\n",
    "\n",
    "for mkey in same_comment_different_code:\n",
    "    mth_in_060 = jf060_methods[mkey]\n",
    "    mth_in_071 = jf071_methods[mkey]\n",
    "    \n",
    "    if is_coherent(mth_in_060) == is_coherent(mth_in_071):\n",
    "        same_coherence.append(mkey)\n",
    "    else:\n",
    "        coherence_changed.append(mkey)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Number of Methods sharing the same lead comment but have different code 32\n",
      "\t Same Coherence:  32\n",
      "\t Different Coherence 0\n"
     ]
    }
   ],
   "source": [
    "print('Total Number of Methods sharing the same lead comment but have different code', len(same_comment_different_code))\n",
    "print('\\t Same Coherence: ', len(same_coherence))\n",
    "print('\\t Different Coherence', len(coherence_changed))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\r\n",
      "   * Creates a scatter plot with default settings.\r\n",
      "   * @param title The chart title.\r\n",
      "   * @param xAxisLabel A label for the X-axis.\r\n",
      "   * @param yAxisLabel A label for the Y-axis.\r\n",
      "   * @param data The dataset for the chart.\r\n",
      "   * @param legend A flag specifying whether or not a legend is required.\r\n",
      "   */\n",
      "\n",
      "  public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel,\r\n",
      "                         XYDataset data, boolean legend) {\r\n",
      "\r\n",
      "    JFreeChart chart = null;\r\n",
      "\r\n",
      "  try {\r\n",
      "      Axis xAxis = new HorizontalNumberAxis(xAxisLabel);\r\n",
      "    Axis yAxis = new VerticalNumberAxis(yAxisLabel);\r\n",
      "      XYPlot plot = new XYPlot(xAxis, yAxis);\r\n",
      "      plot.setXYItemRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES));\r\n",
      "    chart = new JFreeChart(data, plot, title, JFreeChart.DEFAULT_TITLE_FONT, legend);\r\n",
      "  }\r\n",
      "  catch (AxisNotCompatibleException e) {\r\n",
      "      // this won't happen unless you mess with the axis constructors above\r\n",
      "    System.err.println(\"ChartFactory.createScatterPlot(...) : axis not compatible.\");\r\n",
      "  }\r\n",
      "  catch (PlotNotCompatibleException e) {\r\n",
      "      // this won't happen unless you mess with the axis constructors above\r\n",
      "    System.err.println(\"ChartFactory.createScatterPlot(...) : plot not compatible.\");\r\n",
      "  }\r\n",
      "\r\n",
      "    return chart;\r\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Creates a scatter plot with default settings.\r\n",
      "\n",
      "   * @param title The chart title.\r\n",
      "\n",
      "   * @param xAxisLabel A label for the X-axis.\r\n",
      "\n",
      "   * @param yAxisLabel A label for the Y-axis.\r\n",
      "\n",
      "   * @param data The dataset for the chart.\r\n",
      "\n",
      "   * @param legend A flag specifying whether or not a legend is required.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel,\r\n",
      "\n",
      "                         XYDataset data, boolean legend) {\r\n",
      "\n",
      "    ValueAxis xAxis = new HorizontalNumberAxis(xAxisLabel);\r\n",
      "\n",
      "    ValueAxis yAxis = new VerticalNumberAxis(yAxisLabel);\r\n",
      "\n",
      "    XYPlot plot = new XYPlot(xAxis, yAxis);\r\n",
      "\n",
      "    plot.setXYItemRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES));\r\n",
      "\n",
      "    JFreeChart chart = new JFreeChart(data, plot, title, JFreeChart.DEFAULT_TITLE_FONT, legend);\r\n",
      "\n",
      "    return chart;\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\n",
      "   * Selects an appropriate tick value for the axis.  The strategy is to display as many ticks as\n",
      "   * possible (selected from an array of 'standard' tick units) without the labels overlapping.\n",
      "   * @param g2 The graphics device;\n",
      "   * @param drawArea The area in which the plot and axes should be drawn;\n",
      "   * @param plotArea The area in which the plot should be drawn;\n",
      "   */\n",
      "\n",
      "  private void selectAutoTickUnit(Graphics2D g2, Rectangle2D drawArea, Rectangle2D plotArea) {\n",
      "    // calculate the tick label height...\n",
      "    FontRenderContext frc = g2.getFontRenderContext();\n",
      "    double tickLabelHeight = tickLabelFont.getLineMetrics(\"123\", frc).getHeight()\n",
      "                 +this.tickLabelInsets.top+this.tickLabelInsets.bottom;\n",
      "    // now find the smallest tick unit that will accommodate the labels...\n",
      "  double zero = this.translatedValue(Plot.ZERO, plotArea);\n",
      "    // start with the current tick unit...\n",
      "    NumberTickUnit candidate1\n",
      "             = (NumberTickUnit)this.standardTickUnits.getNearestTickUnit(this.tickUnit);\n",
      "    double y = this.translatedValue(candidate1.getValue(), plotArea);\n",
      "    double unitHeight = Math.abs(y-zero);\n",
      "    // then extrapolate...\n",
      "    double bestguess = (tickLabelHeight/unitHeight) * candidate1.value.doubleValue();\n",
      "    NumberTickUnit guess = new NumberTickUnit(new Double(bestguess), null);\n",
      "    NumberTickUnit candidate2\n",
      "               = (NumberTickUnit)this.standardTickUnits.getNearestTickUnit(guess);\n",
      "    this.tickUnit = candidate2;\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\r\n",
      "   * Selects an appropriate tick value for the axis.  The strategy is to display as many ticks as\r\n",
      "\r\n",
      "   * possible (selected from an array of 'standard' tick units) without the labels overlapping.\r\n",
      "\r\n",
      "   * @param g2 The graphics device;\r\n",
      "\r\n",
      "   * @param drawArea The area in which the plot and axes should be drawn;\r\n",
      "\r\n",
      "   * @param plotArea The area in which the plot should be drawn;\r\n",
      "\r\n",
      "   */\n",
      "\n",
      "  private void selectAutoTickUnit(Graphics2D g2, Rectangle2D drawArea, Rectangle2D plotArea) {\r\n",
      "\r\n",
      "    // calculate the tick label height...\r\n",
      "\r\n",
      "    FontRenderContext frc = g2.getFontRenderContext();\r\n",
      "\r\n",
      "    double tickLabelHeight = tickLabelFont.getLineMetrics(\"123\", frc).getHeight()\r\n",
      "\r\n",
      "                 +this.tickLabelInsets.top+this.tickLabelInsets.bottom;\r\n",
      "\r\n",
      "    // now find the smallest tick unit that will accommodate the labels...\r\n",
      "\r\n",
      "  double zero = this.translateValueToJava2D(0.0, plotArea);\r\n",
      "\r\n",
      "    // start with the current tick unit...\r\n",
      "\r\n",
      "    NumberTickUnit candidate1\r\n",
      "\r\n",
      "             = (NumberTickUnit)this.standardTickUnits.getNearestTickUnit(this.tickUnit);\r\n",
      "\r\n",
      "    double y = this.translateValueToJava2D(candidate1.getValue().doubleValue(), plotArea);\r\n",
      "\r\n",
      "    double unitHeight = Math.abs(y-zero);\r\n",
      "\r\n",
      "    // then extrapolate...\r\n",
      "\r\n",
      "    double bestguess = (tickLabelHeight/unitHeight) * candidate1.value.doubleValue();\r\n",
      "\r\n",
      "    NumberTickUnit guess = new NumberTickUnit(new Double(bestguess), null);\r\n",
      "\r\n",
      "    NumberTickUnit candidate2\r\n",
      "\r\n",
      "               = (NumberTickUnit)this.standardTickUnits.getNearestTickUnit(guess);\r\n",
      "\r\n",
      "    this.tickUnit = candidate2;\r\n",
      "\r\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\r\n",
      "   * Creates and returns a default instance of a VerticalXYBarChart based on the specified\r\n",
      "   * dataset.\r\n",
      "   * @param title The chart title.\r\n",
      "   * @param xAxisLabel A label for the X-axis.\r\n",
      "   * @param yAxisLabel A label for the Y-axis.\r\n",
      "   * @param data The dataset for the chart.\r\n",
      "   * @param legend A flag specifying whether or not a legend is required.\r\n",
      "   */\n",
      "\n",
      "  public static JFreeChart createVerticalXYBarChart(String title, String xAxisLabel,\r\n",
      "                            String yAxisLabel, IntervalXYDataset data,\r\n",
      "                            boolean legend) {\r\n",
      "\r\n",
      "    JFreeChart chart = null;\r\n",
      "\r\n",
      "  try {\r\n",
      "    HorizontalDateAxis timeAxis = new HorizontalDateAxis(xAxisLabel);\r\n",
      "    Axis valueAxis = new VerticalNumberAxis(yAxisLabel);\r\n",
      "    Plot plot = new VerticalXYBarPlot(timeAxis, valueAxis, new Insets(0,0,0,0), Color.white,\r\n",
      "      new BasicStroke(), Color.gray);\r\n",
      "    chart = new JFreeChart(data, plot, title, JFreeChart.DEFAULT_TITLE_FONT, legend);\r\n",
      "  }\r\n",
      "  catch (AxisNotCompatibleException e) {\r\n",
      "      // this won't happen unless you mess with the axis constructors above\r\n",
      "    System.err.println(\"ChartFactory.createVerticalXYBarChart(...) : axis not compatible.\");\r\n",
      "  }\r\n",
      "  catch (PlotNotCompatibleException e) {\r\n",
      "      // this won't happen unless you mess with the axis constructors above\r\n",
      "    System.err.println(\"ChartFactory.createVerticalXYBarChart(...) : plot not compatible.\");\r\n",
      "  }\r\n",
      "\r\n",
      "    return chart;\r\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Creates and returns a default instance of a VerticalXYBarChart based on the specified\r\n",
      "\n",
      "   * dataset.\r\n",
      "\n",
      "   * @param title The chart title.\r\n",
      "\n",
      "   * @param xAxisLabel A label for the X-axis.\r\n",
      "\n",
      "   * @param yAxisLabel A label for the Y-axis.\r\n",
      "\n",
      "   * @param data The dataset for the chart.\r\n",
      "\n",
      "   * @param legend A flag specifying whether or not a legend is required.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public static JFreeChart createVerticalXYBarChart(String title, String xAxisLabel,\r\n",
      "\n",
      "                            String yAxisLabel, IntervalXYDataset data,\r\n",
      "\n",
      "                            boolean legend) {\r\n",
      "\n",
      "    HorizontalDateAxis timeAxis = new HorizontalDateAxis(xAxisLabel);\r\n",
      "\n",
      "    ValueAxis valueAxis = new VerticalNumberAxis(yAxisLabel);\r\n",
      "\n",
      "    //Plot plot = new VerticalXYBarPlot(timeAxis, valueAxis, new Insets(0,0,0,0), Color.white,\r\n",
      "\n",
      "    //                  new BasicStroke(), Color.gray);\r\n",
      "\n",
      "    XYPlot plot = new XYPlot(timeAxis, valueAxis, new Insets(0,0,0,0), Color.white,\r\n",
      "\n",
      "                 new BasicStroke(), Color.gray);\r\n",
      "\n",
      "    plot.setXYItemRenderer(new VerticalXYBarRenderer());\r\n",
      "\n",
      "    JFreeChart chart = new JFreeChart(data, plot, title, JFreeChart.DEFAULT_TITLE_FONT, legend);\r\n",
      "\n",
      "    return chart;\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\n",
      "   * Draws the plot on a Java 2D graphics device (such as the screen or a printer).\n",
      "   * @param g2 The graphics device;\n",
      "   * @param drawArea The area within which the chart should be drawn.\n",
      "   * @param plotArea The area within which the plot should be drawn (a subset of the drawArea).\n",
      "   */\n",
      "\n",
      "  public void draw(Graphics2D g2, Rectangle2D drawArea, Rectangle2D plotArea) {\n",
      "  // draw the axis label\n",
      "  if (this.label!=null) {\n",
      "    g2.setFont(labelFont);\n",
      "    g2.setPaint(labelPaint);\n",
      "    Rectangle2D labelBounds = labelFont.getStringBounds(label, g2.getFontRenderContext());\n",
      "    if (labelDrawnVertical) {\n",
      "    double xx = drawArea.getX()+labelInsets.left+labelBounds.getHeight();\n",
      "    double yy = plotArea.getY()+plotArea.getHeight()/2+(labelBounds.getWidth()/2);\n",
      "    drawVerticalString(label, g2, (float)xx, (float)yy);\n",
      "    }\n",
      "    else {\n",
      "    double xx = drawArea.getX()+labelInsets.left;\n",
      "    double yy = drawArea.getY()+drawArea.getHeight()/2-labelBounds.getHeight()/2;\n",
      "    g2.drawString(label, (float)xx, (float)yy);\n",
      "    }\n",
      "  }\n",
      "  // draw the tick labels and marks and gridlines\n",
      "  this.refreshTicks(g2, drawArea, plotArea);\n",
      "  double xx = plotArea.getX();\n",
      "  g2.setFont(tickLabelFont);\n",
      "  Iterator iterator = ticks.iterator();\n",
      "  while (iterator.hasNext()) {\n",
      "    Tick tick = (Tick)iterator.next();\n",
      "    float yy = (float)this.translatedValue(tick.getNumericalValue(), plotArea);\n",
      "    if (tickLabelsVisible) {\n",
      "    g2.setPaint(this.tickLabelPaint);\n",
      "    g2.drawString(tick.getText(), tick.getX(), tick.getY());\n",
      "    }\n",
      "    if (tickMarksVisible) {\n",
      "    g2.setStroke(this.getTickMarkStroke());\n",
      "    Line2D mark = new Line2D.Double(plotArea.getX()-2, yy,\n",
      "            plotArea.getX()+2, yy);\n",
      "    g2.draw(mark);\n",
      "    }\n",
      "    if (showGridLines) {\n",
      "    g2.setStroke(gridStroke);\n",
      "    g2.setPaint(gridPaint);\n",
      "    Line2D gridline = new Line2D.Double(xx, yy,\n",
      "              plotArea.getMaxX(), yy);\n",
      "    g2.draw(gridline);\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\r\n",
      "   * Draws the plot on a Java 2D graphics device (such as the screen or a printer).\r\n",
      "\r\n",
      "   * @param g2 The graphics device;\r\n",
      "\r\n",
      "   * @param drawArea The area within which the chart should be drawn.\r\n",
      "\r\n",
      "   * @param plotArea The area within which the plot should be drawn (a subset of the drawArea).\r\n",
      "\r\n",
      "   */\r\n",
      "\r\n",
      "\n",
      "\n",
      "  public void draw(Graphics2D g2, Rectangle2D drawArea, Rectangle2D plotArea) {\r\n",
      "\r\n",
      "  // draw the axis label\r\n",
      "\r\n",
      "  if (this.label!=null) {\r\n",
      "\r\n",
      "    g2.setFont(labelFont);\r\n",
      "\r\n",
      "    g2.setPaint(labelPaint);\r\n",
      "\r\n",
      "    Rectangle2D labelBounds = labelFont.getStringBounds(label, g2.getFontRenderContext());\r\n",
      "\r\n",
      "    if (labelDrawnVertical) {\r\n",
      "\r\n",
      "    double xx = drawArea.getX()+labelInsets.left+labelBounds.getHeight();\r\n",
      "\r\n",
      "    double yy = plotArea.getY()+plotArea.getHeight()/2+(labelBounds.getWidth()/2);\r\n",
      "\r\n",
      "    drawVerticalString(label, g2, (float)xx, (float)yy);\r\n",
      "\r\n",
      "    }\r\n",
      "\r\n",
      "    else {\r\n",
      "\r\n",
      "    double xx = drawArea.getX()+labelInsets.left;\r\n",
      "\r\n",
      "    double yy = drawArea.getY()+drawArea.getHeight()/2-labelBounds.getHeight()/2;\r\n",
      "\r\n",
      "    g2.drawString(label, (float)xx, (float)yy);\r\n",
      "\r\n",
      "    }\r\n",
      "\r\n",
      "  }\r\n",
      "\r\n",
      "  // draw the tick labels and marks and gridlines\r\n",
      "\r\n",
      "  this.refreshTicks(g2, drawArea, plotArea);\r\n",
      "\r\n",
      "  double xx = plotArea.getX();\r\n",
      "\r\n",
      "  g2.setFont(tickLabelFont);\r\n",
      "\r\n",
      "  Iterator iterator = ticks.iterator();\r\n",
      "\r\n",
      "  while (iterator.hasNext()) {\r\n",
      "\r\n",
      "    Tick tick = (Tick)iterator.next();\r\n",
      "\r\n",
      "    float yy = (float)this.translateValueToJava2D(tick.getNumericalValue(), plotArea);\r\n",
      "\r\n",
      "    if (tickLabelsVisible) {\r\n",
      "\r\n",
      "    g2.setPaint(this.tickLabelPaint);\r\n",
      "\r\n",
      "    g2.drawString(tick.getText(), tick.getX(), tick.getY());\r\n",
      "\r\n",
      "    }\r\n",
      "\r\n",
      "    if (tickMarksVisible) {\r\n",
      "\r\n",
      "    g2.setStroke(this.getTickMarkStroke());\r\n",
      "\r\n",
      "    Line2D mark = new Line2D.Double(plotArea.getX()-2, yy,\r\n",
      "\r\n",
      "            plotArea.getX()+2, yy);\r\n",
      "\r\n",
      "    g2.draw(mark);\r\n",
      "\r\n",
      "    }\r\n",
      "\r\n",
      "    if (gridLinesVisible) {\r\n",
      "\r\n",
      "    g2.setStroke(gridStroke);\r\n",
      "\r\n",
      "    g2.setPaint(gridPaint);\r\n",
      "\r\n",
      "    Line2D gridline = new Line2D.Double(xx, yy,\r\n",
      "\r\n",
      "              plotArea.getMaxX(), yy);\r\n",
      "\r\n",
      "    g2.draw(gridline);\r\n",
      "\r\n",
      "\n",
      "================================================================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Try to spot some insights\n",
    "randomly_pick_a_method_from(same_comment_different_code, with_code=True, with_coherence=True)  # Method 1\n",
    "randomly_pick_a_method_from(same_comment_different_code, with_code=True, with_coherence=True)  # Method 2\n",
    "randomly_pick_a_method_from(same_comment_different_code, with_code=True, with_coherence=True)  # Method 3\n",
    "randomly_pick_a_method_from(same_comment_different_code, with_code=True, with_coherence=True)  # Method 4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"tw05\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Take Away No. 5:\n",
    "\n",
    "Among those methods sharing the **same** lead comments but have differences in the implementations ($32$ in total), \n",
    "**None** of them have differences in the coherence evaluation.\n",
    "This means that differences in the implementation were limited to syntactic constructs and names of the variables."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"dcomm_scode_coherence\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Coherence of Methods with Different Comments but the Same Code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "same_coherence = list()\n",
    "coherence_changed = list()\n",
    "\n",
    "for mkey in different_comment_same_code:\n",
    "    mth_in_060 = jf060_methods[mkey]\n",
    "    mth_in_071 = jf071_methods[mkey]\n",
    "    \n",
    "    if is_coherent(mth_in_060) == is_coherent(mth_in_071):\n",
    "        same_coherence.append(mkey)\n",
    "    else:\n",
    "        coherence_changed.append(mkey)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Number of Methods having different comment but the same code 16\n",
      "\t Same Coherence:  14\n",
      "\t Different Coherence 2\n"
     ]
    }
   ],
   "source": [
    "print('Total Number of Methods having different comment but the same code', len(different_comment_same_code))\n",
    "print('\\t Same Coherence: ', len(same_coherence))\n",
    "print('\\t Different Coherence', len(coherence_changed))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\n",
      "   * Returns the Paint used to color the grid lines (if visible).\n",
      "   */\n",
      "\n",
      "  public Paint getGridPaint() {\n",
      "  return gridPaint;\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  False\n",
      "/**\r\n",
      "\n",
      "   * Returns the grid line color.\r\n",
      "\n",
      "   * @return The grid line color.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public Paint getGridPaint() {\r\n",
      "\n",
      "  return gridPaint;\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\n",
      "   * Adds a horizontal line at location with given color.\n",
      "   * @return void\n",
      "   */\n",
      "\n",
      "  public void addHorizontalLine(Number location, Paint color) {\n",
      "    if (horizontalLines == null) {\n",
      "      horizontalLines = new ArrayList();\n",
      "      horizontalColors = new ArrayList();\n",
      "    }\n",
      "    horizontalColors.add(color);\n",
      "    horizontalLines.add(location);\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  False\n",
      "/**\r\n",
      "\n",
      "   * Adds a horizontal line at the specified data value, using the specified color.\r\n",
      "\n",
      "   * @param value The data value.\r\n",
      "\n",
      "   * @param color The line color.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public void addHorizontalLine(Number location, Paint color) {\r\n",
      "\n",
      "    if (horizontalLines == null) {\r\n",
      "\n",
      "      horizontalLines = new ArrayList();\r\n",
      "\n",
      "      horizontalColors = new ArrayList();\r\n",
      "\n",
      "    }\r\n",
      "\n",
      "    horizontalColors.add(color);\r\n",
      "\n",
      "    horizontalLines.add(location);\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Try to slpot some insights\n",
    "randomly_pick_a_method_from(coherence_changed, with_code=True, with_coherence=True)  # Method 1\n",
    "randomly_pick_a_method_from(coherence_changed, with_code=True, with_coherence=True)  # Method 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"tw06\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Take Away No. 6:\n",
    "\n",
    "This is **interesting**.\n",
    "\n",
    "There are just **2** cases in which differences in comments (and **not** in implementation) lead to different coherence evaluations.\n",
    "\n",
    "As a matter of facts, the changes in the lead comments for methods gathered from _JFreeChart 0.7.1_ are not compliant\n",
    "with the corresponding code. For instance, in the latter case, \n",
    "the parameters listed in the Javadoc `@param` annotations are not all compliant with the corresponding method signature.\n",
    "This phenomenon may be likely due to refactoring changes (i.e. renaming of variables) not reflected in the comment."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Pick some examples from those methods who share the same coherence evaluations (instead)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\r\n",
      "   * Returns the format object used to format tick labels.\r\n",
      "   */\n",
      "\n",
      "  public SimpleDateFormat getTickLabelFormatter() {\r\n",
      "  return tickLabelFormatter;\r\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Returns the formatter for the tick labels.\r\n",
      "\n",
      "   * @return The formatter for the tick labels.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public SimpleDateFormat getTickLabelFormatter() {\r\n",
      "\n",
      "  return tickLabelFormatter;\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  False\n",
      "/**\n",
      "   * Returns chart's backgroud area\n",
      "   */\n",
      "\n",
      "  protected Shape calculateBackgroundPlotArea(Rectangle2D plotArea) {\n",
      "    return plotArea;\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  False\n",
      "/**\r\n",
      "\n",
      "   * Returns chart's background area.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  protected Shape calculateBackgroundPlotArea(Rectangle2D plotArea) {\r\n",
      "\n",
      "    return plotArea;\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  False\n",
      "/**\r\n",
      "   * Full constructor - builds a new DateTitle with the specified attributes.\r\n",
      "   * @param location the relative location of this title (use constants in AbstractTitle);\r\n",
      "   * @param alignment the text alignment of this title (use constants in AbstractTitle);\r\n",
      "   * @param dateStyle the Date style to use (SHORT, MEDIUM, LONG, or FULL constants from\r\n",
      "   *          java.text.DateFormat);\r\n",
      "   * @param locale the locale to use to format this date (if you are unsure what to use here, use\r\n",
      "   *         Locale.getDefault() for your default locale);\r\n",
      "   * @param font the font used to display the date;\r\n",
      "   * @param paint the paint used to display the date;\r\n",
      "   * @param insets the blank space around the outside of the title;\r\n",
      "   */\n",
      "\n",
      "  public DateTitle(int dateStyle, Locale locale, Font font, Paint paint, int position,\r\n",
      "           int horizontalAlignment, int verticalAlignment, Insets insets) {\r\n",
      "\r\n",
      "    super(DateFormat.getDateInstance(dateStyle, locale).format(new Date()),\r\n",
      "        font, paint, position, horizontalAlignment, verticalAlignment, insets);\r\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  False\n",
      "/**\r\n",
      "\n",
      "   * Constructs a new DateTitle with the specified attributes.\r\n",
      "\n",
      "   * @param location the relative location of this title (use constants in AbstractTitle).\r\n",
      "\n",
      "   * @param alignment the text alignment of this title (use constants in AbstractTitle).\r\n",
      "\n",
      "   * @param dateStyle the Date style to use (SHORT, MEDIUM, LONG, or FULL constants from\r\n",
      "\n",
      "   *          java.text.DateFormat).\r\n",
      "\n",
      "   * @param locale the locale to use to format this date (if you are unsure what to use here, use\r\n",
      "\n",
      "   *         Locale.getDefault() for your default locale).\r\n",
      "\n",
      "   * @param font the font used to display the date.\r\n",
      "\n",
      "   * @param paint the paint used to display the date.\r\n",
      "\n",
      "   * @param insets the blank space around the outside of the title.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public DateTitle(int dateStyle, Locale locale, Font font, Paint paint, int position,\r\n",
      "\n",
      "           int horizontalAlignment, int verticalAlignment, Insets insets) {\r\n",
      "\n",
      "    super(DateFormat.getDateInstance(dateStyle, locale).format(new Date()),\r\n",
      "\n",
      "        font, paint, position, horizontalAlignment, verticalAlignment, insets);\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\r\n",
      "   * Sets the vertical alignment for the title, and notifies any registered listeners of the change.\r\n",
      "   * The constants TOP, MIDDLE and BOTTOM (defined in this class) can be used to specify the\r\n",
      "   * alignment.\r\n",
      "   * @param alignment The new vertical alignment (TOP, MIDDLE or BOTTOM);\r\n",
      "   */\n",
      "\n",
      "  public void setVerticalAlignment(int alignment) {\r\n",
      "    if (this.verticalAlignment!=alignment) {\r\n",
      "      this.verticalAlignment = alignment;\r\n",
      "      notifyListeners(new TitleChangeEvent(this));\r\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Sets the vertical alignment for the title, and notifies any registered listeners of the\r\n",
      "\n",
      "   * change.\r\n",
      "\n",
      "   * The constants TOP, MIDDLE and BOTTOM (defined in this class) can be used to specify the\r\n",
      "\n",
      "   * alignment.\r\n",
      "\n",
      "   * @param alignment The new vertical alignment (TOP, MIDDLE or BOTTOM);\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public void setVerticalAlignment(int alignment) {\r\n",
      "\n",
      "    if (this.verticalAlignment!=alignment) {\r\n",
      "\n",
      "      this.verticalAlignment = alignment;\r\n",
      "\n",
      "      notifyListeners(new TitleChangeEvent(this));\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\r\n",
      "   * Registers an object for notification of changes to the title.\r\n",
      "   * @param listener The object that is being registered.\r\n",
      "   */\n",
      " --------------\n",
      "//notifyListeners(new TitleChangeEvent(this));\r\n",
      " --------------\n",
      "\n",
      "\n",
      "  public void addChangeListener(TitleChangeListener listener) {\r\n",
      "  listeners.add(listener);\r\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\r\n",
      "   * Registers an object for notification of changes to the title.\r\n",
      "\r\n",
      "   * @param listener The object that is being registered.\r\n",
      "\r\n",
      "   */\n",
      "\n",
      "  public void addChangeListener(TitleChangeListener listener) {\r\n",
      "\r\n",
      "  listeners.add(listener);\r\n",
      "\r\n",
      "\n",
      "================================================================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Try to spot some insights\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 1\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 2\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 3\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 4\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"tw07\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Take Away No. 7:\n",
    "\n",
    "This is _also_ **interesting**.\n",
    "\n",
    "In all other cases of common methods having differences in the lead comment but **not** in the implementation, it seems that the corresponding coherence is not affected. \n",
    "\n",
    "As a matter of facts, all the changes and differences in the lead comments for methods gathered from JFreeChart 0.7.1\n",
    "are limited to Javadoc syntax adjustments, typos corrections, and revisions of parameters and method's descriptions.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"dcomm_dcode_coherence\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Coherence of Methods with Different Comments and Code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "same_coherence = list()\n",
    "coherence_changed = list()\n",
    "\n",
    "for mkey in different_comment_and_code:\n",
    "    mth_in_060 = jf060_methods[mkey]\n",
    "    mth_in_071 = jf071_methods[mkey]\n",
    "    \n",
    "    if is_coherent(mth_in_060) == is_coherent(mth_in_071):\n",
    "        same_coherence.append(mkey)\n",
    "    else:\n",
    "        coherence_changed.append(mkey)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Number of Methods having different comment and code 10\n",
      "\t Same Coherence:  9\n",
      "\t Different Coherence 1\n"
     ]
    }
   ],
   "source": [
    "print('Total Number of Methods having different comment and code', len(different_comment_and_code))\n",
    "print('\\t Same Coherence: ', len(same_coherence))\n",
    "print('\\t Different Coherence', len(coherence_changed))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Pick some examples from those methods who share the same coherence evaluations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\r\n",
      "   * Full constructor - builds an abstract title with the specified position and alignment. This\r\n",
      "   * class defines constants for the valid position and alignment values---an\r\n",
      "   * IllegalArgumentException will be thrown if invalid values are passed to this constructor.\r\n",
      "   * @param position The relative position of the title (TOP, BOTTOM, RIGHT and LEFT---or NORTH,\r\n",
      "   *         SOUTH, EAST and WEST if you prefer);\r\n",
      "   * @param horizontalAlignment The horizontal alignment of the title (LEFT, CENTER or RIGHT);\r\n",
      "   * @param verticalAlignment The vertical alignment of the title (TOP, MIDDLE or BOTTOM);\r\n",
      "   * @exception IllegalArgumentException If an invalid location or alignment value is passed;\r\n",
      "   */\n",
      "\n",
      "  protected AbstractTitle(int position, int horizontalAlignment, int verticalAlignment,\r\n",
      "              Insets insets) {\r\n",
      "\r\n",
      "    // check position\r\n",
      "    if (!this.isValidPosition(position)) {\r\n",
      "      throw new IllegalArgumentException(\"AbstractTitle: Invalid position.\");\r\n",
      "    }\r\n",
      "\r\n",
      "    // check the horizontal and vertical alignment\r\n",
      "    if ((horizontalAlignment!=LEFT) &&\r\n",
      "      (horizontalAlignment!=CENTER) &&\r\n",
      "      (horizontalAlignment!=RIGHT)) {\r\n",
      "      throw new IllegalArgumentException(\"AbstractTitle: Invalid horizontal alignment.\");\r\n",
      "    }\r\n",
      "\r\n",
      "    if ((verticalAlignment!=TOP) &&\r\n",
      "      (verticalAlignment!=BOTTOM) &&\r\n",
      "      (verticalAlignment!=MIDDLE)) {\r\n",
      "      throw new IllegalArgumentException(\"AbstractTitle: Invalid vertical alignment.\");\r\n",
      "    }\r\n",
      "\r\n",
      "    this.position = position;\r\n",
      "    this.horizontalAlignment = horizontalAlignment;\r\n",
      "    this.verticalAlignment = verticalAlignment;\r\n",
      "    this.insets = insets;\r\n",
      "    this.listeners = new java.util.ArrayList();\r\n",
      "    this.notify = true;\r\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Constructs a title.\r\n",
      "\n",
      "   * <P>\r\n",
      "\n",
      "   * This class defines constants for the valid position and alignment values---an\r\n",
      "\n",
      "   * IllegalArgumentException will be thrown if invalid values are passed to this constructor.\r\n",
      "\n",
      "   * @param position The relative position of the title (TOP, BOTTOM, RIGHT and LEFT---or NORTH,\r\n",
      "\n",
      "   *         SOUTH, EAST and WEST if you prefer).\r\n",
      "\n",
      "   * @param horizontalAlignment The horizontal alignment of the title (LEFT, CENTER or RIGHT).\r\n",
      "\n",
      "   * @param verticalAlignment The vertical alignment of the title (TOP, MIDDLE or BOTTOM).\r\n",
      "\n",
      "   * @exception IllegalArgumentException If an invalid location or alignment value is passed.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  protected AbstractTitle(int position,\r\n",
      "\n",
      "              int horizontalAlignment, int verticalAlignment, Insets insets) {\r\n",
      "\n",
      "    // check arguments...\r\n",
      "\n",
      "    if (!this.isValidPosition(position)) {\r\n",
      "\n",
      "      throw new IllegalArgumentException(\"AbstractTitle(): Invalid position.\");\r\n",
      "\n",
      "    }\r\n",
      "\n",
      "    if (!AbstractTitle.isValidHorizontalAlignment(horizontalAlignment)) {\r\n",
      "\n",
      "      throw new IllegalArgumentException(\"AbstractTitle(): Invalid horizontal alignment.\");\r\n",
      "\n",
      "    }\r\n",
      "\n",
      "    if (!AbstractTitle.isValidVerticalAlignment(verticalAlignment)) {\r\n",
      "\n",
      "      throw new IllegalArgumentException(\"AbstractTitle(): Invalid vertical alignment.\");\r\n",
      "\n",
      "    }\r\n",
      "\n",
      "    // initialise...\r\n",
      "\n",
      "    this.position = position;\r\n",
      "\n",
      "    this.horizontalAlignment = horizontalAlignment;\r\n",
      "\n",
      "    this.verticalAlignment = verticalAlignment;\r\n",
      "\n",
      "    this.insets = insets;\r\n",
      "\n",
      "    this.listeners = new java.util.ArrayList();\r\n",
      "\n",
      "    this.notify = true;\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\n",
      "   * Standard constructor - builds a VerticalCategoryAxis with mostly default attributes.\n",
      "   * @param label The axis label;\n",
      "   */\n",
      "\n",
      "  public VerticalCategoryAxis(String label) {\n",
      "  super(label);\n",
      "  this.verticalLabel = true;\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Constructs a VerticalCategoryAxis, using default attributes where necessary.\r\n",
      "\n",
      "   * @param label The axis label.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public VerticalCategoryAxis(String label) {\r\n",
      "\n",
      "    this(label,\r\n",
      "\n",
      "       Axis.DEFAULT_AXIS_LABEL_FONT,\r\n",
      "\n",
      "       Axis.DEFAULT_AXIS_LABEL_PAINT,\r\n",
      "\n",
      "       Axis.DEFAULT_TICK_LABEL_INSETS,\r\n",
      "\n",
      "       true, // vertical label\r\n",
      "\n",
      "       true, // category labels visible\r\n",
      "\n",
      "       Axis.DEFAULT_TICK_LABEL_FONT,\r\n",
      "\n",
      "       Axis.DEFAULT_TICK_LABEL_PAINT,\r\n",
      "\n",
      "       Axis.DEFAULT_TICK_LABEL_INSETS,\r\n",
      "\n",
      "       false, // tick marks visible\r\n",
      "\n",
      "       Axis.DEFAULT_TICK_STROKE);\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\n",
      "   * Constructs a value axis.\n",
      "   * @param label The axis label.\n",
      "   */\n",
      "\n",
      "  public ValueAxis(String label) {\n",
      "  super(label);\n",
      "  this.autoRange = true;\n",
      "  this.autoTickUnit = true;\n",
      "  this.showGridLines = true;\n",
      "  this.gridStroke = ValueAxis.DEFAULT_GRID_LINE_STROKE;\n",
      "    this.gridPaint = Color.gray;\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Constructs a value axis, using default values where necessary.\r\n",
      "\n",
      "   * @param label The axis label.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public ValueAxis(String label) {\r\n",
      "\n",
      "  this(label,\r\n",
      "\n",
      "       Axis.DEFAULT_AXIS_LABEL_FONT,\r\n",
      "\n",
      "       Axis.DEFAULT_AXIS_LABEL_PAINT,\r\n",
      "\n",
      "       Axis.DEFAULT_AXIS_LABEL_INSETS,\r\n",
      "\n",
      "       true, // tick labels visible\r\n",
      "\n",
      "       Axis.DEFAULT_TICK_LABEL_FONT,\r\n",
      "\n",
      "       Axis.DEFAULT_TICK_LABEL_PAINT,\r\n",
      "\n",
      "       Axis.DEFAULT_TICK_LABEL_INSETS,\r\n",
      "\n",
      "       true, // tick marks visible\r\n",
      "\n",
      "       Axis.DEFAULT_TICK_STROKE,\r\n",
      "\n",
      "       true, // auto range\r\n",
      "\n",
      "       true, // auto tick unit\r\n",
      "\n",
      "       true, // show grid lines\r\n",
      "\n",
      "       ValueAxis.DEFAULT_GRID_LINE_STROKE,\r\n",
      "\n",
      "       ValueAxis.DEFAULT_GRID_LINE_PAINT,\r\n",
      "\n",
      "       0.0,  // crosshair\r\n",
      "\n",
      "       ValueAxis.DEFAULT_CROSSHAIR_STROKE,\r\n",
      "\n",
      "       ValueAxis.DEFAULT_CROSSHAIR_PAINT);\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\r\n",
      "   * Standard constrcutor - builds an abstract title with the specified position and alignment,\r\n",
      "   * with a default inset of 2 pixels around the title.  This class defines constants for the valid\r\n",
      "   * position and alignment values---an IllegalArgumentException will be thrown if invalid values\r\n",
      "   * are passed to this constructor.\r\n",
      "   * @param position The relative position of the title (TOP, BOTTOM, RIGHT and LEFT---or NORTH,\r\n",
      "   *         SOUTH, EAST and WEST if you prefer);\r\n",
      "   * @param horizontalAlignment The horizontal alignment of the title (LEFT, CENTER or RIGHT);\r\n",
      "   * @param verticalAlignment The vertical alignment of the title (TOP, MIDDLE or BOTTOM);\r\n",
      "   * @exception IllegalArgumentException If an invalid location or alignment value is passed;\r\n",
      "   */\n",
      "\n",
      "  protected AbstractTitle(int position, int horizontalAlignment, int verticalAlignment) {\r\n",
      "    this(position, horizontalAlignment, verticalAlignment, new Insets(2, 2, 2, 2));\r\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Constructs a title.\r\n",
      "\n",
      "   * @param position The relative position of the title (TOP, BOTTOM, RIGHT and LEFT---or NORTH,\r\n",
      "\n",
      "   *         SOUTH, EAST and WEST if you prefer);\r\n",
      "\n",
      "   * @param horizontalAlignment The horizontal alignment of the title (LEFT, CENTER or RIGHT);\r\n",
      "\n",
      "   * @param verticalAlignment The vertical alignment of the title (TOP, MIDDLE or BOTTOM);\r\n",
      "\n",
      "   * @exception IllegalArgumentException If an invalid location or alignment value is passed;\r\n",
      "\n",
      "   */\n",
      "\n",
      "  protected AbstractTitle(int position, int horizontalAlignment, int verticalAlignment) {\r\n",
      "\n",
      "    this(position,\r\n",
      "\n",
      "       horizontalAlignment, verticalAlignment,\r\n",
      "\n",
      "       AbstractTitle.DEFAULT_INSETS);\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n",
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  True\n",
      "/**\r\n",
      "   * Sets the gap between the last bar in one category and the first bar in the\r\n",
      "   * next category, and notifies registered listeners that the plot has been modified.\r\n",
      "   * @param gap The new gap value.\r\n",
      "   */\n",
      "\n",
      "  public void setCategoryGapsPercent(double percent) {\r\n",
      "  if (this.categoryGapsPercent!=percent) {\r\n",
      "      this.categoryGapsPercent=Math.min(percent, MAX_CATEGORY_GAPS_PERCENT);\r\n",
      "    notifyListeners(new PlotChangeEvent(this));\r\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Sets the gap between the last bar in one category and the first bar in the\r\n",
      "\n",
      "   * next category, and notifies registered listeners that the plot has been modified.\r\n",
      "\n",
      "   * @param percent The new gap value, expressed as a percentage of the width of the plot area\r\n",
      "\n",
      "   *        (0.05 = 5 percent).\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public void setCategoryGapsPercent(double percent) {\r\n",
      "\n",
      "    // check argument...\r\n",
      "\n",
      "    if ((percent<0.0) || (percent>MAX_CATEGORY_GAPS_PERCENT)) {\r\n",
      "\n",
      "      throw new IllegalArgumentException(\"BarPlot.setCategoryGapsPercent(double): argument \"\r\n",
      "\n",
      "                        +\"outside valid range.\");\r\n",
      "\n",
      "    }\r\n",
      "\n",
      "    // make the change...\r\n",
      "\n",
      "  if (this.categoryGapsPercent!=percent) {\r\n",
      "\n",
      "      this.categoryGapsPercent=percent;\r\n",
      "\n",
      "    notifyListeners(new PlotChangeEvent(this));\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Try to spot some insights\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 1\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 2\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 3\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 4\n",
    "randomly_pick_a_method_from(same_coherence, with_code=True, with_coherence=True)  # Method 5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"tw08\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Take Away No. 8:\n",
    "\n",
    "This is **interesting** as well!!.\n",
    "\n",
    "Among the $10$ methods in common between the two versions that have differences in code and comments, $9$ of them have the same evaluation of coherence.\n",
    "\n",
    "This phenomenon reflects the fact that in these $9$ cases, code and comments have been updated accordingly!\n",
    "\n",
    "However, if we look at the totality of common methods, this number is ridiculous!\n",
    "\n",
    "In more details, it is $9$ methods out of $58$, $\\approx 16\\%$, where $58$ corresponds to $283$ (methods in common) **minus** those with no real difference in code and comments ($225$ - the majority of them)!!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Pick the ONLY example where differences in code and comments have reflected changes in the coherence evaluation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Method in JFreeChart 0.6.0 Is Coherent:  False\n",
      "/**\n",
      "   * Default constructor.\n",
      "   */\n",
      "\n",
      "  public VerticalNumberAxis3D() {\n",
      "  super(null);\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Method in JFreeChart 0.7.1 Is Coherent:  True\n",
      "/**\r\n",
      "\n",
      "   * Constructs a VerticalNumberAxis3D, with no label and default attributes.\r\n",
      "\n",
      "   */\n",
      "\n",
      "  public VerticalNumberAxis3D() {\r\n",
      "\n",
      "  this(null);\r\n",
      "\n",
      "\n",
      "================================================================================\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Try to spot some insights\n",
    "randomly_pick_a_method_from(coherence_changed, with_code=True, with_coherence=True)  # Method 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"tw09\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### Take Away No. 9:\n",
    "\n",
    "This is **interesting** (and **correct**)!!.\n",
    "\n",
    "In the only case (_out of 10_) where there is difference in the coherence evaluation between the two methods in common, the corresponding lead comments and implementations have been updated accordingly!\n",
    "\n",
    "In fact, while there was no coherence for the method extracted from _JFreeChart 0.6.0_, there is for the one from _JfreeChart 0.7.1_."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"difference_methods\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "\n",
    "# Analysis of Methods NOT in Common"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total No. of Methods in JfreeChart 0.6.0 and NOT in 0.7.1:  178\n",
      "--------------------------------------------------------------------------------\n",
      "Total No. of Methods in JfreeChart 0.7.1 and NOT in 0.6.0:  305\n"
     ]
    }
   ],
   "source": [
    "methods_in_060 = set(jf060_methods.keys())\n",
    "methods_in_071 = set(jf071_methods.keys())\n",
    "\n",
    "# Set of Methods in 0.6.0 and not in 0.7.1\n",
    "methods_in_060_not_in_071 = methods_in_060.difference(methods_in_071)\n",
    "print('Total No. of Methods in JfreeChart 0.6.0 and NOT in 0.7.1: ', len(methods_in_060_not_in_071))\n",
    "\n",
    "print('-'*80)\n",
    "\n",
    "# Set of Methods in 0.7.1 and not in 0.6.0\n",
    "methods_in_071_not_in_060 = methods_in_071.difference(methods_in_060)\n",
    "print('Total No. of Methods in JfreeChart 0.7.1 and NOT in 0.6.0: ', len(methods_in_071_not_in_060))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Percentage of Coherente / Not Coherent Methods \n",
    "\n",
    "Analyse how many of the methods in the difference between the two versions are **Coherent** or **Not Coherent**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"diff_jf060\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### JFreeChart 0.6.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Number of Methods in JFreeChart 0.6.0 but NOT in 0.7.1: 178\n",
      "\t Coherent:  146\n",
      "\t Not Coherent 32\n"
     ]
    }
   ],
   "source": [
    "coherent = list()\n",
    "not_coherent = list()\n",
    "\n",
    "for mkey in methods_in_060_not_in_071:\n",
    "    method = jf060_methods[mkey]\n",
    "    if is_coherent(method):\n",
    "        coherent.append(mkey)\n",
    "    else:\n",
    "        not_coherent.append(mkey)\n",
    "        \n",
    "print('Total Number of Methods in JFreeChart 0.6.0 but NOT in 0.7.1:', len(methods_in_060_not_in_071))\n",
    "print('\\t Coherent: ', len(coherent))\n",
    "print('\\t Not Coherent', len(not_coherent))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"diff_jf071\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "### JFreeChart 0.7.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Number of Methods in JFreeChart 0.7.1 but NOT in 0.6.0: 305\n",
      "\t Coherent:  256\n",
      "\t Not Coherent 49\n"
     ]
    }
   ],
   "source": [
    "coherent = list()\n",
    "not_coherent = list()\n",
    "\n",
    "for mkey in methods_in_071_not_in_060:\n",
    "    method = jf071_methods[mkey]\n",
    "    if is_coherent(method):\n",
    "        coherent.append(mkey)\n",
    "    else:\n",
    "        not_coherent.append(mkey)\n",
    "        \n",
    "print('Total Number of Methods in JFreeChart 0.7.1 but NOT in 0.6.0:', len(methods_in_071_not_in_060))\n",
    "print('\\t Coherent: ', len(coherent))\n",
    "print('\\t Not Coherent', len(not_coherent))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"match\"></a> <a href=\"#nav\">Back to top</a>\n",
    "\n",
    "## (Likely) Modified Methods from JFreeChart 0.6.0 to 0.7.1\n",
    "\n",
    "In this section, the main purpose of the analysis is to try to check some possible matches between methods **not in JFreeChart 0.6.0** but present in **JFreeChart 0.7.1**.\n",
    "\n",
    "The main idea is that we would like to find (or guess) all those methods whose signature has been changed/updated thus not appearing in the set of **Common Methods**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Analyse the differences: Try to guess if there is some method that has been CHANGED between the two versions\n",
    "from collections import defaultdict\n",
    "associations_map = defaultdict(list)\n",
    "\n",
    "def match(method_key, target_class, target_file, target_signature_stub):\n",
    "    \"\"\"We try to infer a possible matching between two methods if they share:\n",
    "    - the same class name\n",
    "    - the same source file name\n",
    "    - their signature starts with the same _stub_\n",
    "        In particular, the `target_signature_stub` corresponds to the \n",
    "        first part of the signature till the first open paranthesis, i.e. \"(\"\n",
    "    \"\"\"\n",
    "    mth = jf060_methods[method_key]\n",
    "    return (method_key not in jf071_methods and \n",
    "            mth.code_class.src_filename == target_file \n",
    "            and mth.code_class.class_name == target_class and \n",
    "            signature(mth.code_fragment).startswith(target_signature_stub))\n",
    "    \n",
    "\n",
    "# Iterate over all methods in JFreeChart 0.7.1 and NOT in 0.6.0\n",
    "# in order to guess some possible signature matchings\n",
    "for mkey in methods_in_071_not_in_060:\n",
    "    method = jf071_methods[mkey]\n",
    "    signature_071 = signature(method.code_fragment)\n",
    "    \n",
    "    # get all the methods whose signature starts similarly to the target method\n",
    "    signature_stub = signature_071[:signature_071.find('(')]\n",
    "    class_name = method.code_class.class_name\n",
    "    src_file = method.code_class.src_filename\n",
    "    associations = list(filter(lambda k: match(k, class_name, src_file, signature_stub), \n",
    "                               jf060_methods.keys()))\n",
    "    associations_map[mkey] = associations\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Filter out all that had no matching in the first place\n",
    "possible_mappings = {k:v for k, v in associations_map.items() if len(v)}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "We inferred a total of 28 matchings for 305 methods NOT in common!\n"
     ]
    }
   ],
   "source": [
    "print('We inferred a total of {} matchings for {} methods NOT in common!'.format(len(possible_mappings), \n",
    "                                                                                 len(methods_in_071_not_in_060)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Target Signature:  public HorizontalBarPlot(Axis horizontalAxis, Axis verticalAxis)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  HorizontalBarPlot.javaHorizontalBarPlotpublic HorizontalBarPlot(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "\t 2):  HorizontalBarPlot.javaHorizontalBarPlotpublic HorizontalBarPlot(Axis horizontalAxis, Axis verticalAxis, Insets insets, double introGapPercent, double trailGapPercent, double categoryGapPercent, double seriesGapPercent) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  private void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  XYPlot.javaXYPlotprivate void drawVerticalLines(Graphics2D g2, Rectangle2D plotArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public void draw(Graphics2D g2, Rectangle2D plotArea, DrawInfo info)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  VerticalBarPlot.javaVerticalBarPlotpublic void draw(Graphics2D g2, Rectangle2D drawArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public HorizontalBarPlot(Axis horizontalAxis, Axis verticalAxis, Insets insets, double introGapPercent, double trailGapPercent, double categoryGapPercent, double itemGapPercent, CategoryToolTipGenerator toolTipGenerator)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  HorizontalBarPlot.javaHorizontalBarPlotpublic HorizontalBarPlot(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "\t 2):  HorizontalBarPlot.javaHorizontalBarPlotpublic HorizontalBarPlot(Axis horizontalAxis, Axis verticalAxis, Insets insets, double introGapPercent, double trailGapPercent, double categoryGapPercent, double seriesGapPercent) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalNumberAxis3D(String label, Font labelFont, Paint labelPaint, Insets labelInsets, boolean verticalLabel, boolean showTickLabels, Font tickLabelFont, Paint tickLabelPaint, Insets tickLabelInsets, boolean showTickMarks, Stroke tickMarkStroke, boolean autoRange, boolean autoRangeIncludesZero, Number autoRangeMinimum, double minimumAxisValue, double maximumAxisValue, boolean inverted, boolean autoTickUnit, NumberTickUnit tickUnit, boolean showGridLines, Stroke gridStroke, Paint gridPaint, double crosshairValue, Stroke crosshairStroke, Paint crosshairPaint, double effect3d)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalNumberAxis3D.javaVerticalNumberAxis3Dpublic VerticalNumberAxis3D(String label, Font labelFont, Paint labelPaint, Insets labelInsets, boolean verticalLabel, boolean showTickLabels, Font tickLabelFont, Paint tickLabelPaint, Insets tickLabelInsets, boolean showTickMarks, Stroke tickMarkStroke, boolean autoRange, boolean autoRangeIncludesZero, Number autoRangeMinimum, Number minimumAxisValue, Number maximumAxisValue, boolean autoTickUnit, NumberTickUnit tickUnit, /*Number tickValue, DecimalFormat formatter,*/ boolean showGridLines, Stroke gridStroke, Paint gridPaint, double effect3d)\n",
      "\n",
      "\t 2):  VerticalNumberAxis3D.javaVerticalNumberAxis3Dpublic VerticalNumberAxis3D(String label, Font labelFont, Number minimumAxisValue, Number maximumAxisValue)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalBarPlot(CategoryAxis horizontalAxis, ValueAxis verticalAxis)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalBarPlot.javaVerticalBarPlotpublic VerticalBarPlot(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "\t 2):  VerticalBarPlot.javaVerticalBarPlotpublic VerticalBarPlot(Axis horizontal, Axis vertical, Insets insets, double introGapPercent, double trailGapPercent, double categoryGapPercent, double seriesGapPercent) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalBarPlot3D(CategoryAxis horizontalAxis, ValueAxis verticalAxis)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalBarPlot3D.javaVerticalBarPlot3Dpublic VerticalBarPlot3D(Axis horizontal, Axis vertical, Insets insets, double introGap, double trailGap, double categoryGap, double seriesGap) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "\t 2):  VerticalBarPlot3D.javaVerticalBarPlot3Dpublic VerticalBarPlot3D(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public void addHorizontalLine(Number value)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  XYPlot.javaXYPlotpublic void addHorizontalLine(Number location)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  protected void drawBars(Graphics2D g2, Shape backgroundPlotArea, Rectangle2D plotArea, DrawInfo info)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  VerticalBarPlot3D.javaVerticalBarPlot3Dprotected void drawBars(Graphics2D g2, Shape backgroundPlotArea, Rectangle2D plotArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalXYBarPlot(Axis horizontalAxis, Axis verticalAxis, Insets insets, Paint background, Stroke outlineStroke, Paint outlinePaint)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalXYBarPlot.javaVerticalXYBarPlotpublic VerticalXYBarPlot(Axis horizontalAxis, Axis verticalAxis, Insets insets, Paint background, Stroke outlineStroke, Paint outlinePaint) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "\t 2):  VerticalXYBarPlot.javaVerticalXYBarPlotpublic VerticalXYBarPlot(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalCategoryAxis(String label, Font labelFont, Paint labelPaint, Insets labelInsets, boolean verticalLabel, boolean categoryLabelsVisible, Font categoryLabelFont, Paint categoryLabelPaint, Insets categoryLabelInsets, boolean tickMarksVisible, Stroke tickMarkStroke)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  VerticalCategoryAxis.javaVerticalCategoryAxispublic VerticalCategoryAxis(String label, Font labelFont, Paint labelPaint, Insets labelInsets, boolean verticalLabel, boolean showTickLabels, Font tickLabelFont, Paint tickLabelPaint, Insets tickLabelInsets, boolean showTickMarks, Stroke tickMarkStroke)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  private void drawVerticalLines(Graphics2D g2, Rectangle2D dataArea)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  XYPlot.javaXYPlotprivate void drawVerticalLines(Graphics2D g2, Rectangle2D plotArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalNumberAxis(String label, Font labelFont, Paint labelPaint, Insets labelInsets, boolean labelDrawnVertical, boolean tickLabelsVisible, Font tickLabelFont, Paint tickLabelPaint, Insets tickLabelInsets, boolean tickMarksVisible, Stroke tickMarkStroke, boolean autoRange, boolean autoRangeIncludesZero, Number autoRangeMinimum, double minimumAxisValue, double maximumAxisValue, boolean inverted, boolean autoTickUnitSelection, NumberTickUnit tickUnit, boolean gridLinesVisible, Stroke gridStroke, Paint gridPaint, double crosshairValue, Stroke crosshairStroke, Paint crosshairPaint)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalNumberAxis.javaVerticalNumberAxispublic VerticalNumberAxis(String label, Font labelFont, Paint labelPaint, Insets labelInsets, boolean labelDrawnVertical, boolean tickLabelsVisible, Font tickLabelFont, Paint tickLabelPaint, Insets tickLabelInsets, boolean tickMarksVisible, Stroke tickMarkStroke, boolean autoRange, boolean autoRangeIncludesZero, Number autoRangeMinimum, Number minimumAxisValue, Number maximumAxisValue, boolean autoTickUnitSelection, NumberTickUnit tickUnit, boolean gridLinesVisible, Stroke gridStroke, Paint gridPaint)\n",
      "\n",
      "\t 2):  VerticalNumberAxis.javaVerticalNumberAxispublic VerticalNumberAxis(String label, Font labelFont, Number minimumAxisValue, Number maximumAxisValue)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public void draw(Graphics2D g2, Rectangle2D plotArea, DrawInfo info)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  XYPlot.javaXYPlotpublic void draw(Graphics2D g2, Rectangle2D drawArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalBarPlot(CategoryAxis horizontalAxis, ValueAxis verticalAxis, Insets insets, double introGapPercent, double trailGapPercent, double categoryGapPercent, double itemGapPercent, CategoryToolTipGenerator toolTipGenerator)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalBarPlot.javaVerticalBarPlotpublic VerticalBarPlot(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "\t 2):  VerticalBarPlot.javaVerticalBarPlotpublic VerticalBarPlot(Axis horizontal, Axis vertical, Insets insets, double introGapPercent, double trailGapPercent, double categoryGapPercent, double seriesGapPercent) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalNumberAxis(String label, Font labelFont, double minimumAxisValue, double maximumAxisValue)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalNumberAxis.javaVerticalNumberAxispublic VerticalNumberAxis(String label, Font labelFont, Paint labelPaint, Insets labelInsets, boolean labelDrawnVertical, boolean tickLabelsVisible, Font tickLabelFont, Paint tickLabelPaint, Insets tickLabelInsets, boolean tickMarksVisible, Stroke tickMarkStroke, boolean autoRange, boolean autoRangeIncludesZero, Number autoRangeMinimum, Number minimumAxisValue, Number maximumAxisValue, boolean autoTickUnitSelection, NumberTickUnit tickUnit, boolean gridLinesVisible, Stroke gridStroke, Paint gridPaint)\n",
      "\n",
      "\t 2):  VerticalNumberAxis.javaVerticalNumberAxispublic VerticalNumberAxis(String label, Font labelFont, Number minimumAxisValue, Number maximumAxisValue)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalNumberAxis3D(String label, Font labelFont, double minimumAxisValue, double maximumAxisValue)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalNumberAxis3D.javaVerticalNumberAxis3Dpublic VerticalNumberAxis3D(String label, Font labelFont, Paint labelPaint, Insets labelInsets, boolean verticalLabel, boolean showTickLabels, Font tickLabelFont, Paint tickLabelPaint, Insets tickLabelInsets, boolean showTickMarks, Stroke tickMarkStroke, boolean autoRange, boolean autoRangeIncludesZero, Number autoRangeMinimum, Number minimumAxisValue, Number maximumAxisValue, boolean autoTickUnit, NumberTickUnit tickUnit, /*Number tickValue, DecimalFormat formatter,*/ boolean showGridLines, Stroke gridStroke, Paint gridPaint, double effect3d)\n",
      "\n",
      "\t 2):  VerticalNumberAxis3D.javaVerticalNumberAxis3Dpublic VerticalNumberAxis3D(String label, Font labelFont, Number minimumAxisValue, Number maximumAxisValue)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public void setHorizontalAxis(Axis axis)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  BarPlot.javaBarPlotpublic void setHorizontalAxis(Axis axis) throws AxisNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public void draw(Graphics2D g2, Rectangle2D drawArea, DrawInfo info)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  VerticalXYBarPlot.javaVerticalXYBarPlotpublic void draw(Graphics2D g2, Rectangle2D drawArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public void setVerticalAxis(Axis axis)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  BarPlot.javaBarPlotpublic void setVerticalAxis(Axis axis) throws AxisNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  private void drawHorizontalLines(Graphics2D g2, Rectangle2D dataArea)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  XYPlot.javaXYPlotprivate void drawHorizontalLines(Graphics2D g2, Rectangle2D plotArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  private void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  XYPlot.javaXYPlotprivate void drawHorizontalLines(Graphics2D g2, Rectangle2D plotArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  protected void drawBars(Graphics2D g2, Shape backgroundPlotArea, Rectangle2D dataArea, DrawInfo info)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  VerticalBarPlot.javaVerticalBarPlotprotected void drawBars(Graphics2D g2, Shape backgroundPlotArea, Rectangle2D plotArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public void draw(Graphics2D g2, Rectangle2D plotArea, DrawInfo info)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  HorizontalBarPlot.javaHorizontalBarPlotpublic void draw(Graphics2D g2, Rectangle2D drawArea)\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalBarPlot3D(CategoryAxis horizontalAxis, ValueAxis verticalAxis, Insets insets, double introGap, double trailGap, double categoryGap, double seriesGap, CategoryToolTipGenerator toolTipGenerator)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalBarPlot3D.javaVerticalBarPlot3Dpublic VerticalBarPlot3D(Axis horizontal, Axis vertical, Insets insets, double introGap, double trailGap, double categoryGap, double seriesGap) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "\t 2):  VerticalBarPlot3D.javaVerticalBarPlot3Dpublic VerticalBarPlot3D(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public VerticalXYBarPlot(Axis horizontalAxis, Axis verticalAxis)\n",
      "Possible Associations in Total:  2\n",
      "\t 1):  VerticalXYBarPlot.javaVerticalXYBarPlotpublic VerticalXYBarPlot(Axis horizontalAxis, Axis verticalAxis, Insets insets, Paint background, Stroke outlineStroke, Paint outlinePaint) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "\t 2):  VerticalXYBarPlot.javaVerticalXYBarPlotpublic VerticalXYBarPlot(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public XYPlot(ValueAxis horizontalAxis, ValueAxis verticalAxis, Insets insets, Paint background, Stroke outlineStroke, Paint outlinePaint)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  XYPlot.javaXYPlotpublic XYPlot(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "Target Signature:  public XYPlot(ValueAxis horizontalAxis, ValueAxis verticalAxis)\n",
      "Possible Associations in Total:  1\n",
      "\t 1):  XYPlot.javaXYPlotpublic XYPlot(Axis horizontalAxis, Axis verticalAxis) throws AxisNotCompatibleException, PlotNotCompatibleException\n",
      "\n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "# Print Matchings Guessed\n",
    "for mkey, associations in possible_mappings.items():\n",
    "    print('Target Signature: ', signature(jf071_methods[mkey].code_fragment))\n",
    "    print('Possible Associations in Total: ', len(associations))\n",
    "    for i, assoc in enumerate(associations):\n",
    "        print('\\t {}): '.format(i+1), assoc, end=\"\\n\\n\")\n",
    "    print('-'*80)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Conclusion\n",
    "Most of the guessed matchings are reasonable - most of them have just one possible match. \n",
    "Of course, we should manually dive more deeply into the code to check whether or not these methods actually corresponds to the _same_ methods that has been changed between the two versions.\n",
    "\n",
    "However, we may conclude that most of the methods present in the **JFreeChart 0.7.1** version (but not in version 0.6.0) have been **added** in the new version!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"summary\"></a> <a href=\"#nav\">Back to top</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "# Summary\n",
    "\n",
    "* JFreeChart 0.6.0 and 0.7.1 have $283$ methods in common \n",
    "    - For each systems, methods are uniquely identified by a the tuple: \n",
    "        `(Name of the File, Name of the Class, Method Signature)`.\n",
    "    - Methods with the same tuple in both systems are thus considered the **same** method.\n",
    "\n",
    "* **Methods in Common** have been further analysed (and grouped) in terms of similarities (differences) in their lead comment and implementation. In more details:\n",
    "\n",
    "    * **As for the Comment**:\n",
    "        - $257$ methods have the same lead comment (apart from some differences in layout and formattings)\n",
    "        - $26$ methods have different lead comments.\n",
    "        \n",
    "    * **As for the Implementation**:\n",
    "        \n",
    "        - $225$ methods sharing the **same** comment have (also) the same comment;\n",
    "        - $32$ methods sharing the **same** comment have different implementation.\n",
    "        \n",
    "        Similarly:\n",
    "        - $16$ methods share the **same** code but have different comments;\n",
    "        - $10$ methods have differences in code and comment\n",
    "    \n",
    "* **As for the Coherence**:\n",
    "    - For methods with the same code and same comment\n",
    "        - There is **no** difference in coherence (crosscheck) **as expected**\n",
    "    - For methods with the same comment but different code, we have\n",
    "        - We experienced **no** difference as well. In fact, changes in code are limited to small refactoring operations (e.g. variable renaming or `try catch` blocks addition) which did not affect the semantic of the whole implementation.\n",
    "        \n",
    "    - For methods with different comment but the same code, we have:\n",
    "        - $14$ methods having the same coherence evaluation\n",
    "        - $2$ methods have different coherence\n",
    "        In the first case, changes in comments reflect small adjustments in the Javadoc syntax as well as \n",
    "        revisions in the method's description.\n",
    "        On ther hand, the two cases in which there were differences in the coherence refer to \n",
    "        methods in which the lead comments are not aligned with the corresponding implementation (only partial changes to the comments).\n",
    "        \n",
    "    - For methods with different code and comment, we have:\n",
    "        - $9$ methods have the same coherence evaluation. This means that in these cases both comments and implementations have been updated accordingly in the two versions.\n",
    "        - $1$ method has different coherence evaluation. In this particular example, changes in comment and implementations improved the coherence of this method. In fact, this method was non-coherent in JFreeChart 0.6.0, while it is finally coherent in version 0.7.1. "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
